<?php
// 其他模板页面
Route::get('/admin/tpl/{name}', function ($name) {
    return view('admin.otherpage.' . $name);
});
//提示消息
Route::get("/tips", function () {
    return view("errors.tips");
});
// 获取验证码地址
Route::get("/captcha/{tmp}", "Admin\LoginController@captcha");
// 前台登陆验证
Route::post("/logTodo", "Admin\LoginController@logTodo");
// 后台登陆验证
Route::post("/home/logTodo", "Home\LoginController@logTodo");

// ======== 后台管理路由 ============
Route::group(['namespace' => 'Admin', 'prefix' => 'admin', 'middleware' => 'admin'], function () {
    // 模板页面
    Route::get('list/{tmp?}', 'IndexController@lists'); // 列表页模板
    Route::get('edit', 'IndexController@edit'); // 编辑添加页面
    
    // 登录退出
    Route::get("/login", "LoginController@login");
    Route::get("/logout", "LoginController@logout");
    
    // 后台首页
    Route::get('/', 'IndexController@index');
    Route::get('index', 'IndexController@index');
    
    /* ============= 商品管理 ==================== */
    // 商品分类管理
    Route::get('category/create/{pid?}', 'CategoryController@create');
    Route::post('category/isshow', 'CategoryController@showHidden');
    Route::post('category/isnav', 'CategoryController@isNav');
    Route::resource('category', 'CategoryController');
    
    // 商品管理模块
    Route::post('goods/issale', 'GoodsController@issale');
    Route::post('goods/delete', 'GoodsController@destroy');
    Route::post('goods/uploadone', 'GoodsController@uploadone');
    Route::resource('goods', 'GoodsController');
    
    // 商品属性管理
    Route::post('attr', 'GoodsAttrController@store');
    Route::post('attr/update', 'GoodsAttrController@update');
    Route::get('attr/delete', 'GoodsAttrController@destroy');
    
    // 商品图片管理
    Route::get('album/add/{id}', 'GoodsAlbumController@create');
    Route::post('album/add/{id}', 'GoodsAlbumController@uploadMore');
    /* ========================================== */
    
    /* ============= 订单与评价 ==================== */
    // 订单管理页
    Route::any('/order', "OrderController@order");
    Route::get('/order/xiugai/{id}', "OrderController@detail"); // 订单管理页->查看订单详情
    Route::get('/xiugai/{id}/status', "OrderController@status"); //订单管理业->查看订单详情->发货
    Route::post('/xiugai/{id}/edit', "OrderController@edit"); //订单管理业->查看订单详情->发货
    
    //用户评价路由
    Route::get('/comment/delete/{id}', 'CommentController@destroy');
    Route::resource("comment", "CommentController");
    /* ========================================== */
    
    /* ============= 会员管理 ==================== */
    // 普通会员管理
    Route::get('/edit', 'IndexController@edit');
    Route::get("user", "UserController@index");
    Route::match(["get", "post"], "user", "UserController@index");
    Route::get("user/create", "UserController@create");
    Route::get("user/delete/{id}", "UserController@delete");
    Route::post("user/store", "UserController@store");
    Route::resource("user", "UserController");
    
    // 管理员管理
    Route::match(["get", "post"], "admin", "AdminUserController@index");//搜索表单路由
    Route::post("admin/store", "AdminUserController@store");//管理员添加
    Route::get("admin/delete/{id}", "AdminUserController@destroy");//删除管理员
    Route::resource("admin", "AdminUserController");// 管理员列表
    Route::post("admin/setGroup", "AdminUserController@setGroup");//ajax请求 修改管理员分组
    /* ========================================== */

    /* ============= 权限管理 ==================== */
    // 分组管理
    Route::get("group/delete/{id}", "GroupController@destroy");//删除分组路由
    Route::post("group/setRule", "Groupcontroller@setRule");//设置分组路由
    Route::resource("group", "GroupController");
    
    // 权限管理
    Route::post('rule/multi', 'RuleController@multi');
    Route::post('rule/delete', 'RuleController@delete');
    Route::resource('rule', 'RuleController');
    /* ========================================== */
    
    /* ============= 内容管理 ==================== */
    // 系统消息通知模块
    Route::get('/getmessage', 'MessageController@getMessage');
    Route::resource('message', 'MessageController');
    
    //问题反馈
    Route::get("feedback/delete/{id}", "FeedBackController@destroy");//删除反馈问题
    Route::resource("feedback", "FeedBackController");
    
    // 帮助中心
    Route::post('faq/multi', 'FaqController@multi');
    Route::post('faq/delete', 'FaqController@delete');
    Route::resource('faq/fc', 'FaqCategoryController');
    
    // 帮助中心
    Route::get('faq/add/{id?}', 'FaqController@create');
    Route::get('faq/delete/{id}', 'FaqController@destroy');
    Route::resource('faq', 'FaqController');
    /* ========================================== */
    
    /* ============= 系统管理 ==================== */
    // 网站配置模块
    Route::post('system/save', 'SystemController@save');
    Route::get('system/all', 'SystemController@getConfigs');
    Route::resource('system', 'SystemController');
    
    // 广告管理
    Route::post('ads/upload', 'AdsController@uploadone');
    Route::post('ads/isopen', 'AdsController@isopen');
    Route::resource('ads', 'AdsController');
    Route::post('ads/delete', 'AdsController@destroy');
    
    // 友情链接管理
    Route::post('links/isopen', 'LinksController@isopen');
    Route::post('links/order', 'LinksController@changeOrder');
    Route::resource('links', 'LinksController');
    Route::post('links/delete', 'LinksController@destroy');
    /* ========================================== */
});

// ======== 前台管理路由公共模块 ============
Route::group(['namespace' => 'Home'], function () {
    // 登录注册
    Route::get("/login", "LoginController@login");
    Route::get("/sign", "IndexController@create");
    Route::post("/store", "LoginController@store");     // 执行注册
    
    // 网站首页页面
    Route::get('/', 'IndexController@index');
    
    // 商品页面
    Route::get('/list/{id?}', 'GoodsController@GoodsList'); // 商品列表页
    Route::get('/item/{id}', 'GoodsController@GoodsItem');  // 商品详情页
    Route::get('/item/getnum/{id}', 'GoodsController@getNum');  // ajax获取商品数量
    Route::get('/item/{gid}/{aid}', 'GoodsController@getGoodsAttr');    // ajax获取商品属性信息
    
    // 友情链接申请
    Route::get('/links', 'LinksController@index');
    Route::post('/links', 'LinksController@store');
    
    // 帮助中心路由
    Route::get('/faq/{id?}', 'FaqController@index');
});

// ======== 前台管理路由登录用户模块 ============
Route::group(['namespace' => 'Home', 'middleware'=>'user'], function () {
    // 退出
    Route::get("/logout", "LoginController@logout");
    
    // 购物车
    Route::get('/shopcar', 'ShopcarController@index');
    Route::get('/shopcar/add', 'ShopcarController@addCar');
    Route::get("/shopcar/delete/{id?}", "ShopcarController@deleteCar");
    Route::get("/shopcar/update", "ShopcarController@updateCar");
    Route::get('/shopcar/getcartnum', 'ShopcarController@getCartNum');
    
    // 订单确认支付
    Route::get("/confirm", "OrderController@index");    // 订单列表
    Route::get("/order", "OrderController@index"); // 订单列表
    Route::post('/order/changeaddress', 'OrderController@changeAddress'); // 订单页面修改收货地址
    Route::any("/confirm/{id}/status", "OrderController@status"); //*订单页面 默认地址
    Route::get("/confirm/processing", "OrderController@processing");//*订单页面 提交订单
    Route::get("/confirm/success", "OrderController@success");//*订单页面 购买成功
    
    /* ============= 个人中心  ==================== */
    // 订单管理
    Route::any("/user", "UserController@index");    // 订单列表
    Route::get('/order/shou/{id}', 'OrderController@shou'); // 确认收货
    // 订单评价
    Route::get('/comment/{id}', 'UserController@comment');
    Route::post('/comment', 'UserController@commentAdd');
    
    // 收货地址管理
    Route::get("/address", "AddressController@index");
    Route::get("/getAddress", "AddressController@getAddress");
    Route::get("/address/delete/{id}", "AddressController@destroy"); // 删除收货地址
    Route::post("/address/{id}/edit", "AddressController@editAddress");// 编辑收获地址
    Route::any("/address/{id}/status", "AddressController@status");// 编辑默认地址
    Route::post("/address/add", "AddressController@addressTodo");// 收获地址处理
    
    // 我的收藏
    Route::post('/user/favorite', 'FavoriteController@index');
    Route::get('/user/myfavorite', "FavoriteController@getAllFavorite");
    Route::get('/user/favorite/cancel', "FavoriteController@delete");
    
    // 站内消息
    Route::get('/user/message', 'MessageController@index');
    Route::get('/user/message/read/{id}', 'MessageController@show');
    Route::get('/user/message/readall', 'MessageController@readall');
    Route::get('/user/message/delete/{id}', 'MessageController@delete');
    Route::get('/user/message/deleteall', 'MessageController@deleteall');
    
    // 资料修改
    Route::get("/user/edit", "UserController@edit");
    Route::post("/user/edit", "UserController@update");
    Route::post("/user/avartar", "UserController@avartar");
    /* ========================================== */
    
    // 问题反馈
    Route:get('/home/feedback', 'FeedbackController@index');    // 显示页面
    Route::post("/home/feedback/add", "FeedbackController@store");  // 执行添加
});